<?php
// 
//  common.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-06-08.
//  Copyright 2011 lishuzu. All rights reserved.
// 
/**
* 通用类
*/
class Common
{
	
	function __construct()
	{
		$this->CI = &get_instance();
		$this->user = $this->CI->session->userdata('user') ? $this->CI->session->userdata('user') : '';
		$this->CI->load->model('pm_model');
		$this->CI->load->model('notification_model');
		$this->CI->load->model('security_model');
	}
	//检查站点是否关闭
	function checkclose() {
		$site_config = $this->CI->config->item('site_config');
		//站点关闭
		if($site_config['close'] && $this->CI->uri->segment(1) != 'admin') {
			if(empty($site_config['closereason'])) {
				showmessage('对不起本站暂时关闭');
			} else {
				showmessage($site_config['closereason']);
			}
		}
		return true;
	}
	
	// 检查是否有新的邮件
	public function checknewpm(){
		if (!get_cookie('checkpm')) {
			//检查当前用户
			if($this->user) {
				$mynewpm = $this->CI->pm_model->check_newpm($this->user['uid']);
				if($this->user['newpm'] != $mynewpm) {
					$this->CI->db->where('uid', $this->user['uid']);
					$this->CI->db->update('user', array('newpm' => $mynewpm));
					// 更新session
					$this->CI->security_model->update_user_session();
				}
			}
			ssetcookie('checkpm', 1, 30);
		}
	}
	
	// 检查是否有新的提醒
	public function checknewnotice(){
		if (!get_cookie('checknotice')) {
			//检查当前用户
			if($this->user) {
				$mynewnotice = $this->CI->notification_model->check_newnotice($this->user['uid']);
				if($this->user['notenum'] != $mynewnotice) {
					// 更新session
					$this->CI->security_model->update_user_session();
				}
			}
			ssetcookie('checknotice', 1, 30);
		}

	}
}
?>